package com.accessibleworlds.report;

import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import com.accessibleworlds.R;

public class CustomListAdapter extends ArrayAdapter<Comment>
{
	Context context;
	int layoutResourceId;    
	ArrayList<Comment> data;
	
	public CustomListAdapter(Context context, int layoutResourceId, ArrayList<Comment> data) 
	{
		super(context,layoutResourceId,data);
		this.layoutResourceId = layoutResourceId;
		this.context=context;
		this.data = data;
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		View row = convertView;
		MyStringReaderHolder holder;

		if(row==null)
		{
			LayoutInflater inflater = ((Activity)context).getLayoutInflater();
			row = inflater.inflate(layoutResourceId, parent,false);

			holder= new MyStringReaderHolder();

			holder.from = (TextView)row.findViewById(R.id.from);
			holder.body = (TextView)row.findViewById(R.id.body);

			row.setTag(holder);
		}
		else
		{
			holder=(MyStringReaderHolder) row.getTag();
		}

		holder.from.setText(data.get(position).user.toString());
		holder.body.setText(data.get(position).comment.toString());
		return row;
	}
	static class MyStringReaderHolder
	{
		TextView from,body;
	}
}
